package com.example.checkout.mapper;

import com.example.checkout.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 获取所有用户
     *
     * @return 用户列表
     */
    @Select("SELECT * FROM user")
    List<User> getAllUsers();

    /**
     * 根据ID查找用户
     *
     * @param user_id 用户ID
     * @return 用户对象
     */
    @Select("SELECT * FROM user WHERE user_id = #{user_id}")
    User getUserById(Integer user_id);

    /**
     * 插入用户
     *
     * @param user 用户对象
     */
    @Insert("INSERT INTO user (name, borrowedBooks, checkout, money, card, borrowTime, returnTime, permission) " +
        "VALUES (#{name}, #{borrowedBooks}, #{checkout}, #{money}, #{card}, #{borrowTime}, #{returnTime}, #{permission})")
    void insertUser(User user);

    /**
     * 更新用户
     *
     * @param user 用户对象
     */
    @Update("UPDATE user SET name = #{name}, borrowedBooks = #{borrowedBooks}, checkout = #{checkout}, money = #{money}, " +
        "card = #{card}, borrowTime = #{borrowTime}, returnTime = #{returnTime}, permission = #{permission} " +
        "WHERE user_id = #{user_id}")
    void updateUser(User user);

    /**
     * 根据ID删除用户
     *
     * @param user_id 用户ID
     */
    @Delete("DELETE FROM user WHERE user_id = #{user_id}")
    void deleteUser(Integer user_id);
}